//
//  ZYOAuthViewController.swift
//  ZYweibo
//
//  Created by 张耀 on 16/6/27.
//  Copyright © 2016年 zhangyao. All rights reserved.
//

import UIKit

class ZYOAuthViewController: UIViewController {

    override func loadView() {
        
        view = webView
    }
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        shitu()
    }
    
    // MARK: - 监听事件
    
    @objc private func jiantingClick(){
    
        dismissViewControllerAnimated(true, completion: nil )
        
    }
    
    
    @objc private func anniuClick(){
    
        print("按钮点击了")
    }
    
    // MARK: - 设置导航栏
    
    
    
    
    

    private func daohanglan(){
    
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", style: UIBarButtonItemStyle.Plain, target: self, action: "jiantingClick")
    
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "自动填充", style: UIBarButtonItemStyle.Plain, target: self, action: "anniuClick")
        
        navigationItem.title = "登录界面"
    }
    
    // MARK: - 设置视图
    private func shitu(){
    
        view.backgroundColor = UIColor.whiteColor()

        daohanglan()
    }
    
    // MARK: - 懒加载控件
    private lazy var webView: UIWebView = {
    
        let view = UIWebView()
        view.delegate = self
        let url = NSURL (string: "https://api.weibo.com/oauth2/authorize?client_id=\(APPKEY)&redirect_uri=\(REDIRECT_URI)")!
        let request = NSURLRequest(URL: url)
        view.loadRequest(request)
        
        return view
    
    }()
    
}

extension ZYOAuthViewController:UIWebViewDelegate{

    func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        
        print(request.URL?.absoluteString)
        return true
    }


}






